 <html>
 <head>
 <title>simple_ci_tpsa_examples.f90</title>                                     
                                                                                
                                           
 </head>
 <body>
PROGRAM PROGRAM_ONE_TURN_MAP <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
USE MADX_PTC_MODULE <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
USE POINTER_LATTICE <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
USE C_TPSA <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
IMPLICIT NONE <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
 <a name="</BR>"></a>
<font color="#0000FF">   <br> INTERFACE </br> </font>                                                                                                                                                                                                                                                                                                                                                                                                                                                               
<font color="#FF0000">   <br> SUBROUTINE BUILD_LATTICE_ALS(ALS,MIS) </br> </font>                                                                                                                                                                                                                                                                                                                                                                                                                                   
         USE MADX_PTC_MODULE <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
         USE POINTER_LATTICE <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
         IMPLICIT NONE <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
         TYPE(LAYOUT), TARGET :: ALS <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
         LOGICAL(LP) MIS <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
 <a name="BUILD_LATTICE_ALS"></a>
<font color="#FF0000">   <br> END SUBROUTINE BUILD_LATTICE_ALS(ALS,MIS) </br> </font>                                                                                                                                                                                                                                                                                                                                                                                                                               
<font color="#0000FF">   <br> END INTERFACE </br> </font>                                                                                                                                                                                                                                                                                                                                                                                                                                                           
TYPE(LAYOUT), POINTER:: ALS <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
REAL(DP) PREC,CLOSED_ORBIT(6),MAT(6,6) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
TYPE(INTERNAL_STATE),TARGET :: STATE <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
LOGICAL(LP) :: MIS=.TRUE. <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
INTEGER I,MAP_ORDER,MF <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
TYPE(REAL_8) Y(6) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
TYPE(DAMAP) MR <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
TYPE(DRAGTFINN) DFR <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
TYPE(C_TAYLOR) CT,DCT,ICT <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
TYPE(C_NORMAL_FORM) NORMAL_FORM <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
TYPE(C_VECTOR_FIELD) DF <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
TYPE(C_FACTORED_LIE) FN <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
TYPE(C_DAMAP)  ONE_TURN_MAP, ID,M1 <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
INTEGER POW(LNV) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
PREC=1.D-6 <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
LONGPRINT=.FALSE. <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
CALL PTC_INI_NO_APPEND <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
CALL APPEND_EMPTY_LAYOUT(M_U) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
ALS=>M_U%START <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
CALL BUILD_LATTICE_ALS(ALS,MIS) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
STATE=DELTA0 <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
MAP_ORDER=3 <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
CALL INIT_ALL(STATE,MAP_ORDER,0) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
WRITE(6,*) " " <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
CALL ALLOC(ONE_TURN_MAP,ID,M1) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
CALL ALLOC(Y) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
CALL ALLOC(NORMAL_FORM) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
CALL ALLOC(CT,DCT,ICT) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
CALL ALLOC(DF) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
CALL ALLOC(MR) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
CALL ALLOC(DFR) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
CALL ALLOC(FN) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
CLOSED_ORBIT=0.D0 <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
CALL FIND_ORBIT_X(ALS,CLOSED_ORBIT(1:6),STATE,1.E-5_DP,FIBRE1=1) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                               
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
ID=1 <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
Y(1:6)=CLOSED_ORBIT(1:6)+ID <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
CALL PROPAGATE(ALS,Y(1:6),STATE,FIBRE1=1) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
ONE_TURN_MAP=Y(1:6) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
MR=ONE_TURN_MAP <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
CLOSED_ORBIT=Y <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
CALL  C_NORMAL(ONE_TURN_MAP,NORMAL_FORM) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
  <a name="CMONO.2"></a>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
WRITE(6,*) "CT= (3+5I)*Z_2" <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
CT=(3.D0+5*I_).CMONO.2 <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
CALL PRINT(CT,6) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
WRITE(6,*) "CT= (2+6I)*Z_2*Z_3^2" <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
POW=0; POW(2)=1;POW(3)=2; <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
CT=(2.D0+6*I_).CMONO.POW <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
CALL PRINT(CT,6) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
WRITE(6,*) "CT= (2+6I)*Z_2*Z_3^2" <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
CT=(2.D0+6*I_).CMONO.'012' <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
CALL PRINT(CT,6) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
WRITE(6,*) "CT= (3)*Z_2" <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
CT=(3.D0).CMONO.2 <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
CALL PRINT(CT,6) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
WRITE(6,*) "CT= (2.D0)*Z_2*Z_3^2" <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
POW=0; POW(2)=1;POW(3)=2; <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
CT=(2.D0).CMONO.POW <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
CALL PRINT(CT,6) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
WRITE(6,*) "CT= (2.D0)*Z_2*Z_3^2" <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
CT=(2.D0).CMONO.'012' <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
CALL PRINT(CT,6) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
WRITE(6,*) " " <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
WRITE(6,*) "CT= (2.D0)*Z_2*Z_3^2 + (2.D0+I)*Z_2*^2*Z_3^1" <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                      
CT=((2.D0).CMONO.'012')+((2.D0+I_).CMONO.'021') <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                
CALL PRINT(CT,6) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
DCT=CT.D.3 <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
WRITE(6,*) "DCT = CT.D.3 = D CT / DZ_3" <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
CALL PRINT(DCT,6) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
WRITE(6,*) " " <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
ICT=DCT.I.3 <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
WRITE(6,*) "ICT = \INT DCT DZ_3 " <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
CALL PRINT(ICT,6) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
CALL KANALNUMMER(MF,"ONE_LIE_FACTORED.TXT") <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
CALL C_FACTOR_MAP(ONE_TURN_MAP,M1,DF,1) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
WRITE(MF,*) " M= DF O M1 " <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
CALL PRINT(M1,MF,PREC) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
WRITE(MF,*) "   DF = EXP(F.GRAD) ID" <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
WRITE(MF,*) "    F IS PRINTED " <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
CALL PRINT(DF,MF,PREC) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
DFR=MR <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
CALL PRINT(DFR,MF) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
CALL C_FACTOR_MAP(ONE_TURN_MAP,M1,DF,-1) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
WRITE(MF,*) "  M= M1 O DF" <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
CALL PRINT(M1,MF,PREC) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
WRITE(MF,*) "   DF = EXP(F.GRAD) ID" <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
WRITE(MF,*) "    F IS PRINTED " <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
CALL PRINT(DF,MF,PREC) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
CLOSE(MF) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
CALL KANALNUMMER(MF,"DRAGT_FINN_FACTORED.TXT") <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
WRITE(MF,*) " THE NONLINEAR PART CANONICAL TRANSFORMATION A OF THE NORMAL FORM " <br>                                                                                                                                                                                                                                                                                                                                                                                                                               
WRITE(MF,*) " FACTORISED AS : EXP(NORMAL_FORM%G%F(NO).GRAD) ... EXP(NORMAL_FORM%G%F(1).GRAD) " <br>                                                                                                                                                                                                                                                                                                                                                                                                                 
FN=NORMAL_FORM%G <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
CALL PRINT(FN,MF,PREC) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
CLOSE(MF) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
CALL KANALNUMMER(MF,"EXPONENTIAL_OPERATORS.TXT") <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                               
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
WRITE(MF,*) " TESTING THE ONE LIE FACTORIZATION " <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                              
ID=TEXP(DF,M1) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
ID=ID**(-1)*ONE_TURN_MAP <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
CALL PRINT(ID,MF,PREC) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
WRITE(MF,*) " TESTING THE FACTORED LIE FACTORIZATION " <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                         
ID=NORMAL_FORM%A1*NORMAL_FORM%A2*FROM_PHASOR() <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
ID=TEXP(NORMAL_FORM%G,ID) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
ID=(ID*FROM_PHASOR(-1))**(-1) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
ID=ID*NORMAL_FORM%A_T <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
CALL PRINT(ID,MF,PREC) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
CLOSE(MF) <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
CALL PTC_END <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
<hr color="#CC0000" size="10" align="left" noshade>                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
END PROGRAM PROGRAM_ONE_TURN_MAP <br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
 </body>
 </html>
